<?php
namespace app\common\model;




class Banner extends Base
{

    public function getTypeTextAttr($value,$data)
    {
        $status = [1=>'跳转外链',2=>'跳转活动详情'];
        return $status[$data['type']];
    }

    public function getList($map = []){
        return $this->alias('b')
            ->join('banner_cate c','c.cid = b.cid','LEFT')
            ->where($map)
            ->order('order')
            ->field('b.*,c.cate_name')
            ->paginate('',false,['query'=>request()->param()]);
    }

    public function getBanner($map = [],$limit = 6)
    {
        $rows =  $this->where($map)->field('bid,url,title,img,type')->order('order')->limit($limit)->select();
        foreach ($rows as $k => $v){
            if ($v['type'] == 1){
                $rows[$k]['content'] = '';
            }else{
                $rows[$k]['content'] = Activity::where('id',$v['url'])->cache(5)->value('content');
            }
        }
        return $rows;

    }


}